{% extends 'HrOnlineBundle::layout.html.twig' %}

{% block body %}

    <header>
        <h1>{% trans %}My Documents{% endtrans %}</h1>
    </header>

	{% include 'HrOnlineBundle:Default:_flashes.html.twig' %}


  <ol id="uploaded_documents">
  {% for document in documents %}
		<li data-id="{{document.id}}">
			<a href="#" class="button small-button remove float-right">{% trans %}delete{% endtrans %}</a>
			<a target="_blank" data-id="{{document.id}}" href="{{document.uploadDir}}{{document.path}}">{{document.type}} - {{document.name}} </a>
		</li>
  {% else %}
  	<li>
		{% trans  %}No files uploaded.{% endtrans %}		
	</li>
  {% endfor %}
  </ol>
	

	<fieldset>
		<legend>{% trans %}New Upload{% endtrans %}</legend>
			<form action="{{ path('hr_online_user_upload') }}" method="post" {{ form_enctype(form) }} class="register">
				{{ form_errors(form) }}

				{{ form_rest(form) }}

				<input type="submit" value="{% trans %}Save{% endtrans %}" />
			</form>
		</legend>
	</fieldset>


	<script type="text/javascript">
	$( ".button.remove" ).button({
		  icons: {
			primary: "ui-icon-trash"
		  },
		  text: false
	});

	$( ".button.remove" ).click(function(){
		 var params = {};
		 var li =  $(this).parent();
		 var id = parseInt( li.data('id') );
		 params['id'] = id;
		 var myAjax = new jQuery.post("{{ path('hr_online_delete_document') }}", params, function(responseText) {
			if (id>0)
			{
				 li.remove();
			}
		 });
		return false;
	});

	</script>


{% endblock %}


